// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

public sealed partial class SpanNearQuery
{
	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("boost")]
	public float? Boost { get; set; }

	/// <summary>
	/// <para>
	/// Array of one or more other span type queries.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("clauses")]
	public ICollection<Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery> Clauses { get; set; }

	/// <summary>
	/// <para>
	/// Controls whether matches are required to be in-order.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("in_order")]
	public bool? InOrder { get; set; }
	[JsonInclude, JsonPropertyName("_name")]
	public string? QueryName { get; set; }

	/// <summary>
	/// <para>
	/// Controls the maximum number of intervening unmatched positions permitted.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("slop")]
	public int? Slop { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.Query(SpanNearQuery spanNearQuery) => Elastic.Clients.Elasticsearch.QueryDsl.Query.SpanNear(spanNearQuery);
	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery(SpanNearQuery spanNearQuery) => Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery.SpanNear(spanNearQuery);
}

public sealed partial class SpanNearQueryDescriptor<TDocument> : SerializableDescriptor<SpanNearQueryDescriptor<TDocument>>
{
	internal SpanNearQueryDescriptor(Action<SpanNearQueryDescriptor<TDocument>> configure) => configure.Invoke(this);

	public SpanNearQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery> ClausesValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument> ClausesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>> ClausesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>>[] ClausesDescriptorActions { get; set; }
	private bool? InOrderValue { get; set; }
	private string? QueryNameValue { get; set; }
	private int? SlopValue { get; set; }

	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor<TDocument> Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Array of one or more other span type queries.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor<TDocument> Clauses(ICollection<Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery> clauses)
	{
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesValue = clauses;
		return Self;
	}

	public SpanNearQueryDescriptor<TDocument> Clauses(Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument> descriptor)
	{
		ClausesValue = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesDescriptor = descriptor;
		return Self;
	}

	public SpanNearQueryDescriptor<TDocument> Clauses(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>> configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorActions = null;
		ClausesDescriptorAction = configure;
		return Self;
	}

	public SpanNearQueryDescriptor<TDocument> Clauses(params Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>>[] configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Controls whether matches are required to be in-order.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor<TDocument> InOrder(bool? inOrder = true)
	{
		InOrderValue = inOrder;
		return Self;
	}

	public SpanNearQueryDescriptor<TDocument> QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Controls the maximum number of intervening unmatched positions permitted.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor<TDocument> Slop(int? slop)
	{
		SlopValue = slop;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (ClausesDescriptor is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ClausesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorAction is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>(ClausesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorActions is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			foreach (var action in ClausesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("clauses");
			JsonSerializer.Serialize(writer, ClausesValue, options);
		}

		if (InOrderValue.HasValue)
		{
			writer.WritePropertyName("in_order");
			writer.WriteBooleanValue(InOrderValue.Value);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (SlopValue.HasValue)
		{
			writer.WritePropertyName("slop");
			writer.WriteNumberValue(SlopValue.Value);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class SpanNearQueryDescriptor : SerializableDescriptor<SpanNearQueryDescriptor>
{
	internal SpanNearQueryDescriptor(Action<SpanNearQueryDescriptor> configure) => configure.Invoke(this);

	public SpanNearQueryDescriptor() : base()
	{
	}

	private float? BoostValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery> ClausesValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor ClausesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor> ClausesDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor>[] ClausesDescriptorActions { get; set; }
	private bool? InOrderValue { get; set; }
	private string? QueryNameValue { get; set; }
	private int? SlopValue { get; set; }

	/// <summary>
	/// <para>
	/// Floating point number used to decrease or increase the relevance scores of the query.
	/// Boost values are relative to the default value of 1.0.
	/// A boost value between 0 and 1.0 decreases the relevance score.
	/// A value greater than 1.0 increases the relevance score.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor Boost(float? boost)
	{
		BoostValue = boost;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Array of one or more other span type queries.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor Clauses(ICollection<Elastic.Clients.Elasticsearch.QueryDsl.SpanQuery> clauses)
	{
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesValue = clauses;
		return Self;
	}

	public SpanNearQueryDescriptor Clauses(Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor descriptor)
	{
		ClausesValue = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = null;
		ClausesDescriptor = descriptor;
		return Self;
	}

	public SpanNearQueryDescriptor Clauses(Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor> configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorActions = null;
		ClausesDescriptorAction = configure;
		return Self;
	}

	public SpanNearQueryDescriptor Clauses(params Action<Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor>[] configure)
	{
		ClausesValue = null;
		ClausesDescriptor = null;
		ClausesDescriptorAction = null;
		ClausesDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Controls whether matches are required to be in-order.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor InOrder(bool? inOrder = true)
	{
		InOrderValue = inOrder;
		return Self;
	}

	public SpanNearQueryDescriptor QueryName(string? queryName)
	{
		QueryNameValue = queryName;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Controls the maximum number of intervening unmatched positions permitted.
	/// </para>
	/// </summary>
	public SpanNearQueryDescriptor Slop(int? slop)
	{
		SlopValue = slop;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (ClausesDescriptor is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, ClausesDescriptor, options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorAction is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor(ClausesDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (ClausesDescriptorActions is not null)
		{
			writer.WritePropertyName("clauses");
			writer.WriteStartArray();
			foreach (var action in ClausesDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.SpanQueryDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("clauses");
			JsonSerializer.Serialize(writer, ClausesValue, options);
		}

		if (InOrderValue.HasValue)
		{
			writer.WritePropertyName("in_order");
			writer.WriteBooleanValue(InOrderValue.Value);
		}

		if (!string.IsNullOrEmpty(QueryNameValue))
		{
			writer.WritePropertyName("_name");
			writer.WriteStringValue(QueryNameValue);
		}

		if (SlopValue.HasValue)
		{
			writer.WritePropertyName("slop");
			writer.WriteNumberValue(SlopValue.Value);
		}

		writer.WriteEndObject();
	}
}